<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Model\Goods;
use App\Model\Assess;
use Auth;
use DB;

class AssessController extends Controller
{
    /**
     * Display a listing of the resource.
     *商品id 订单id 从点击评论带过来的参数
     * @return \Illuminate\Http\Response
     */
    public function index($goods_id,$id)
    {
    
        $goods = Goods::where('goods_id',$goods_id)->first();
        return view('home.asses_add')->with('goods',$goods)->with('id',$id);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *写入评论 更新订单状态
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        
        $assess = new Assess();
        $assess->uid = Auth::user()->id;
        $assess->level = $request->level[0];
        $assess->content = $request->content;
        $assess->goods_id = $request->goods_id;
        $res = $assess->save();
        //更新订单状态到3交易成功
        DB::table('order')
            ->where('id', $request->order_id)
            ->update(['order_status' => 3]);  
        return redirect('orderInfo/');    
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
